package engine.flag 
{
	import engine.data.ObjectData;
	import engine.data.ResPath;
	import engine.data.SceneObject;
	import engine.data.ViewObject;
	import engine.newUi.ActorPropertyUI;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.geom.Matrix;
	
	import newx.com.ResManager;
	import newx.com.control.NxClip;
	import newx.com.loader.SwfLoader;
	
	/**
	 * ...
	 * @author WangHaiBo  www.woniu.com
	 * 资源路径获取管理
	 * 
	 */
	public class ResourcesPath 
	{
		public static function getFightRoleModel(val:SceneObject):String
		{
			var	roleModel:String	=	ResPath.ACTORS + "npc_" + getModelID(val) + ".swf";
			return roleModel
		}
		/**
		 * 获取人物模型
		 * @return
		 */
		public static function getRoleModel(val:SceneObject):String
		{
			var roleModel:String	=	""
			if (val.CheckProperties("Model")) 
			{
				switch (val.Type) 
				{
					case ObjType.TaskNPC:
					case ObjType.TradeNPC:
					case ObjType.FunctionNPC:
					case ObjType.HotelNpc:
					case ObjType.DepotNPC:
					case ObjType.GiftNpc:
					case ObjType.DinnerNpc:
					case ObjType.ForbiddenBox:
					case ObjType.SnowDrift:
						roleModel	=	"funcnpc_";
						break;
					case ObjType.Player:
						roleModel	=	"role_";
						return roleModel	=	ResPath.ACTORS + roleModel + getModelID(val) +".swf";
						//						return roleModel	=	ResPath.ACTORS + "testrole_22011100_1.swf"
						break;
					case ObjType.NPC:
					case ObjType.DragonNPC:
					case ObjType.PetNPC:
					case ObjType.HierogramNPC:
						roleModel	=	"npc_";
						break;
					default:
				}
				roleModel	=	ResPath.ACTORS + roleModel + String(val.GetProperties("Model")) + ".swf";
			}
			return roleModel;
		}
		public static function getModel(val:ObjectData,isFight:Boolean=false):String
		{
			if(val is SceneObject)
			{
				if(isFight)
					return getFightRoleModel(val as SceneObject);
				return getRoleModel(val as SceneObject)
			}
			return getPartnerModel(val as ViewObject)
		}
		/**
		 *得到伙伴人物模型 
		 * @param val
		 * @return 
		 * 
		 */		
		public static  function getPartnerModel(val:ViewObject):String
		{
			return ResPath.ACTORS+"npc_"+val.GetPropertiesEx(ActorPropertyUI.MODEL)+".swf"
		}
		/**
		 * 获取场景模型资源
		 * @return
		 */
		public static function getSceneModel(val:int):String
		{
			return ResPath.SCENE + "scene_" + val + ".swf";
		}
		/**
		 *获取绝学资源 
		 * @param val
		 * @return 
		 * 
		 */		
		public static function getSpecialKungFuModel(val:String):String
		{
			return ResPath.KUNGFU  + val + ".swf";
		}
		
		/**
		 *获取绝学图片资源 
		 * @param model
		 * @return 
		 * 
		 */		
		public static function getSpecialKungFuURL( model : int):String
		{
			return "SpecialKungFuPic_"+ model;
		}
		/**
		 * 获取场景缩略图
		 * @param	val
		 * @return
		 */
		public static function getMinSceneModel( val:int ):String
		{
			return ResPath.SCENE + "scene_" + val + ".swf";
		}
		/**
		 * 获取半身像资源
		 * @param	val
		 * @return
		 */
		public static function getHalfPic( val : int, container : DisplayObjectContainer, scale : int = 1 ):void
		{
			var url : String = "";
			if(!checkModelType(val))
			{
				url = ResPath.PHOTO + "half_" + val + ".swf";
			}
			else
			{
				url = ResPath.PHOTO + "half_" + val + ".swf";
			}
			
			ResManager.loadRes( "half_" + val, url, onComplete );
			
			function onComplete(swf:DisplayObject,pList:Array = null):void
			{
				var mc : MovieClip = ResManager.newResClass( "half_" + val ) as MovieClip;
				
				if( mc == null ) return;
				var bit : Bitmap = new Bitmap( displayObjectPixel( mc, scale ) );
				
				if( container is NxClip )
				{
					( container as NxClip ).source = bit;
				}else
				{
					container.addChild( bit );
				}
			}
		}
		
		/**
		 * mc位图化 
		 * @param mc
		 * @param scale 		缩放比例
		 */
		private static function displayObjectPixel( mc : DisplayObject, scale : Number = 1) : BitmapData
		{
			var bitMapData : BitmapData ;
			//图片有改变
			
			if( 1 != scale )
			{
				bitMapData = new BitmapData( mc.width * scale, mc.height * scale, true, 0 );
				
				
				bitMapData.draw( mc, new Matrix( scale, 0, 0, scale, 0, 0 ) );
			}else
			{
				bitMapData = new BitmapData( mc.width, mc.height, true, 0 )				
				
				bitMapData.draw( mc );
			}
			return bitMapData;
		}
		
		/**
		 * 获取头像
		 * @param	val
		 * @return
		 */
		public static function getHeadPic( val : int, clothModel : int = 0 ):String
		{
			if( clothModel == 0 ) return "head_" + val;
			return "head_" + val + "_" + clothModel;
		}
		
		/**
		 * 获取PVP头像
		 * 
		 */
		public static function getPvpHeadPic(val:int, clothModel:int = 0):String
		{
			if( clothModel == 0 ) return "pvphead_" + val;
			return "pvphead_" + val + "_" + clothModel;
		}
		/**
		 * 获取大的全身像
		 * @param	val
		 * @return
		 */
		public static function getBigHalfPic( val : int ):String
		{
			return ResPath.PHOTO + "bighalf_" + val + ".swf";
		}
		/**
		 *获取小头像 
		 * @param val
		 * @return 
		 * 
		 */		
		public static function getMiniHeadPic( val : int ,clothModel : * = ""):String
		{
			if(clothModel	==	"")
				return "minihead_" + val ;
			if( clothModel == 0 ) 
				clothModel =1;
			return "minihead_" + val + "_" + clothModel;
			
		}
		/**
		 * 获取道具资源
		 * @param	val
		 * @return
		 */
		public static function getPropsURL( model : int):String
		{
			return "icon_" + model;
		}
		/**
		 * 获取人物模型ID号 
		 * @param val
		 * @return 
		 * 
		 */		
		public static function getModelID(val:SceneObject):String
		{
			var modelID:int	;
			if(val.GetPropertiesEx("ModelEx") &&val.GetPropertiesEx("Model")!=val.GetPropertiesEx("ModelEx"))
			{
				modelID = val.GetPropertiesEx("ModelEx");
			}
			else
			{
				modelID = val.GetPropertiesEx("Model");
			}
			
			var roleIndex:int	=	val.GetPropertiesEx("ClotheModel");
			roleIndex		=	roleIndex<1? 1 : roleIndex;
			//			roleIndex ++;
			return String(modelID)+"_" + String(roleIndex);
		}
		
		/**
		 * 判断模型号，为玩家 0，还是NPC  1
		 * @param modelID
		 * @return 
		 * 
		 */		
		private static function checkModelType(modelID:int):int
		{
			var type:int	=	0;
			var checkStr:String	=	String(modelID).substr(0,4);
			if(checkStr == "2201")
			{
				type	=	0
			}
			else
			{
				type	=	1;
			}
			return type;
		}
	}
}